<?php

use Illuminate\Database\Seeder;
use App\Models\User;

class UsersTableSeeder extends Seeder
{
    /**
     * Run the database seeds.
     *
     * @return void
     */
    public function run()
    {
        //获取faker实例
        $faker = app(Faker\Generator::class);
        //头像
        $avatar = [
            'https://fsdhubcdn.phphub.org/uploads/images/201710/14/1/s5ehp11z6s.png?imageView2/1/w/200/h/200',
            'https://fsdhubcdn.phphub.org/uploads/images/201710/14/1/Lhd1SHqu86.png?imageView2/1/w/200/h/200',
            'https://fsdhubcdn.phphub.org/uploads/images/201710/14/1/LOnMrqbHJn.png?imageView2/1/w/200/h/200',
            'https://fsdhubcdn.phphub.org/uploads/images/201710/14/1/xAuDMxteQy.png?imageView2/1/w/200/h/200',
            'https://fsdhubcdn.phphub.org/uploads/images/201710/14/1/ZqM7iaP4CR.png?imageView2/1/w/200/h/200',
            'https://fsdhubcdn.phphub.org/uploads/images/201710/14/1/NDnzMutoxX.png?imageView2/1/w/200/h/200',
        ];
        //生成数据集合
        $users = factory(User::class)->times(10)->make()
                ->each(function ($user,$index) use ($faker,$avatar){
                   $user->avatar = $faker->randomElement($avatar);
                });
        //隐藏可见
        $user_array = $users->makeVisible(['password','remember'])->toArray();
        User::insert($user_array);

        //处理第一个
        $user =User::find(1);
        $user->name = 'summer';
        $user->email = 'summer@yousails.com';
        $user->assignRole('Founder');
        $user->save();
        $user = User::find(2);
        $user->name = '1';
        $user->email = '1@qq.com';
        $user->assignRole('Maintainer');
        $user->save();
    }
}
